#ifndef COMMDATA_H
#define COMMDATA_H

#include <vector>
#include <optional>

struct MessageHeader
{
    uint8_t code_0 = 0;
    uint8_t code_1 = 0;
    uint8_t number = 0;
    uint8_t address = 0;
    uint8_t reserve = 0;
    uint8_t cmd_1 = 0;
    uint8_t cmd_2 = 0;
    uint8_t cmd_3 = 0;
    uint16_t length = 0;
};


struct Message
{
    MessageHeader header;
    std::vector<uint8_t> data;
    uint8_t checksum;
    size_t begin;
    size_t end;
};

class CommData
{
public:
    static std::vector<uint8_t> send(uint8_t cmd_1, uint8_t cmd_2, uint8_t cmd_3, const std::vector<uint8_t> &data);
    static std::optional<Message> recv(const std::vector<uint8_t> &msg);
    static uint8_t checksum(const MessageHeader &header, const std::vector<uint8_t> &data);
    static uint8_t checksum(const std::vector<uint8_t> &data);
};

#endif // COMMDATA_H
